<template>
  <div class="app-container">
    <el-form :inline="true" ref="refForm">
      <el-button class="filter-item" type="primary"  icon="el-icon-search" @click="submitFilterForm">全面检测</el-button>
    </el-form>
    <el-table
      border
      :data="tableData"
      v-loading="loading"
      element-loading-text="加载中..."
      class="el-table-align-center">
      <el-table-column label="序号" type="index" width="50" align="center">
      </el-table-column>
      <el-table-column prop="total" label="域名地址" align="center"></el-table-column>
      <el-table-column prop="ios" label="被墙" align="center"></el-table-column>
      <el-table-column prop="ios" label="未解析" align="center"></el-table-column>
      <el-table-column prop="ios" label="服务器不通" align="center"></el-table-column>
      <el-table-column prop="ios" label="未知错误" align="center"></el-table-column>
      <el-table-column prop="ios" label="域名未授权" align="center"></el-table-column>
      <el-table-column prop="ios" label="被跳转" align="center"></el-table-column>
    </el-table>
  </div>
</template>


<script>
  import {getDomainTestInfoApi as listApi} from "@/services/api/operational";
  import {grid} from '@/build'

  export default {
    name: "system-domain",
    mixins: [grid],
    data() {
      return {
        tableData: [],
      }
    },
    methods: {
      selfResetForm(formName){
        this.resetForm(formName);
        this.submitFilterForm();
      },
      submitFilterForm() {

        this.filters = {...this.filters, project: consts.PLATFROM_PREFIX}
        this.gridSearch()
      },
      getSummaries(param) {
        const {columns, data} = param;
        const sums = [];
        let length = _.keys(columns).length;

        columns.forEach((column, index) => {
          const values = data.map(item => Number(item[column.property]));
          if (index === 0) {
            sums[index] = '汇总';
            return;
          } else if ([1, 2, 3, 4 ,5].indexOf(index) !== -1 && !values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr);
              if (!isNaN(value)) {
                return prev + curr;
              } else {
                return prev;
              }
            }, 0);
          } else {
            sums[index] = '';
          }
        });
        return sums;
      }
    },
    mounted() {

      this.bindGet(listApi, 'tableData', {
        action: 'getGrid',
        sendingData: 'filters',
        // format: data => {
        //   let result = [];
        //   _.forIn(data, (value, key) => {
        //     let login = value.login || {};
        //     let visit = value.visit || {};
        //     let loginFake = {};//分别存各端数量
        //     let loginTotal = 0;//存总数
        //     _.each(login, (item) => {
        //       loginFake[item.name] = item.count;
        //       loginTotal += item.count;
        //     })
        //     result.push({
        //       date: key,
        //       total: loginTotal,
        //       pc: _.formatDiv(loginFake['PC'], loginTotal, {fixed: 2}),
        //       ios: _.formatDiv(loginFake['IOS'], loginTotal, {fixed: 2}),//loginFake['IOS']/loginTotal,
        //       android: _.formatDiv(loginFake['安卓'], loginTotal, {fixed: 2}),//loginFake['安卓']/loginTotal,
        //       h5: _.formatDiv(loginFake['H5'], loginTotal, {fixed: 2}),//loginFake['H5']/loginTotal})
        //     })
        //   })
        //   return result;
        // }
      });
      this.submitFilterForm();
    }

  }
</script>

<style scoped>

</style>
